package com.hrs.core.controller;

import com.hrs.common.anno.NoNeedLogin;
import com.hrs.common.anno.NoValidPrivilege;
import com.hrs.common.constant.SwaggerConst;
import com.hrs.common.doMain.PageResultDto;
import com.hrs.common.result.Result;
import com.hrs.core.service.SalaryScaleService;
import com.hrs.enity.dto.SalaryViewDto;
import com.hrs.enity.ro.SalaryAddRo;
import com.hrs.enity.ro.SalaryPageRo;
import com.hrs.enity.ro.SalaryReviewRo;
import com.hrs.enity.ro.SalaryUpdateRo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @author 摆渡人
 * @description
 * @date 2023/1/13 1:01
 */
@Api(tags = {SwaggerConst.Admin.MANAGER_SALARY})
@RestController
public class SalaryScaleController {

    @Autowired
    private SalaryScaleService salaryScaleService;

    @ApiOperation(value = "增添薪资")
    @PostMapping("/salary/add")
    public Result<String> add(@Validated @RequestBody SalaryAddRo salaryAddRo) {
        return salaryScaleService.add(salaryAddRo);
    }

    @ApiOperation(value = "复核")
    @PostMapping("/salary/review")
    public Result<String> review(@Validated @RequestBody SalaryReviewRo salaryReviewRo) {
        return salaryScaleService.review(salaryReviewRo);
    }

    @ApiOperation(value = "修改")
    @PostMapping("/salary/update")
    public Result<String> update(@Validated @RequestBody SalaryUpdateRo salaryUpdateRo) {
        return salaryScaleService.updateBySid(salaryUpdateRo);
    }

    @ApiOperation(value = "根据id获取一条记录")
    @GetMapping("/salary/{id}")
    public Result<SalaryViewDto> getSalaryById(@PathVariable Long id) {
        return salaryScaleService.getSalaryById(id);
    }

    @ApiOperation("分页查询")
    @PostMapping("/salary/page")
    public Result<PageResultDto<SalaryViewDto>> pageSalary(@Validated @RequestBody SalaryPageRo salaryPageRo) {
        return salaryScaleService.pageSalary(salaryPageRo);
    }

    @ApiOperation("下拉框")
    @GetMapping("/salary/listAll")
    public Result<List<SalaryViewDto>> listSalary(){
        return salaryScaleService.listSalary();
    }

    @ApiOperation("删除")
    @PostMapping("/salary/delete")
    @NoNeedLogin
    public Result<String> deleteSalary(@RequestBody Long id){
        return salaryScaleService.deleteSalary(id);
    }
}
